package com.huaxin.device.mapping;

import com.huaxin.device.dto.enums.AlarmLevel;
import com.huaxin.device.dto.request.AlarmThresholdTemplateCreateReqDTO;
import com.huaxin.device.dto.request.AlarmThresholdTemplateUpdateReqDTO;
import com.huaxin.device.models.AlarmThresholdTemplate;
import com.huaxin.hxenum.enums.DeviceType;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;

@Mapper(componentModel = "spring")
public interface AlarmThresholdTemplateMapping {

    @Mapping(target = "deviceType", ignore = true)
    @Mapping(target = "alarmLevel", ignore = true)
    AlarmThresholdTemplate toEntity(AlarmThresholdTemplateCreateReqDTO in);

    @AfterMapping
    default void afterMapping(AlarmThresholdTemplateCreateReqDTO in, @MappingTarget AlarmThresholdTemplate entity) {
        entity.setDeviceType(DeviceType.of(in.getDeviceType()));
        entity.setAlarmLevel(AlarmLevel.of(in.getAlarmLevel()));
    }

    @Mapping(target = "deviceType", ignore = true)
    @Mapping(target = "alarmLevel", ignore = true)
    void updateEntity(AlarmThresholdTemplateUpdateReqDTO in, @MappingTarget AlarmThresholdTemplate entity);

    @AfterMapping
    default void afterMapping(AlarmThresholdTemplateUpdateReqDTO in, @MappingTarget AlarmThresholdTemplate entity) {
        entity.setDeviceType(DeviceType.of(in.getDeviceType()));
        entity.setAlarmLevel(AlarmLevel.of(in.getAlarmLevel()));
    }
}